<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class M_grade_smiley extends MY_Model {
	
	protected $_table = "grade_smiley";
	protected $_uid = "id";

	public function __construct(){
		parent::__construct();
	}

	public function create_default_data()
	{
		$d[] = array(
				'name' => "Hooray",
				'desc' => "Hooray",
				'color' => "yellow",
				'color_code' => "yellow",
				'level' => "1",
				'icon' => "symb-yellow.png",
			);
		$d[] = array(
				'name' => "Great",
				'desc' => "Great",
				'color' => "red",
				'color_code' => "red",
				'level' => "2",
				'icon' => "symb-red.png",
			);
		$d[] = array(
				'name' => "Nice",
				'desc' => "Nice",
				'color' => "blue",
				'color_code' => "blue",
				'level' => "3",
				'icon' => "symb-blue.png",
			);
		$d[] = array(
				'name' => "Can Do Better",
				'desc' => "Can Do Better",
				'color' => "green",
				'color_code' => "green",
				'level' => "4",
				'icon' => "symb-green.png",
			);
		$d[] = array(
				'name' => "Help",
				'desc' => "Help",
				'color' => "orange",
				'color_code' => "orange",
				'level' => "5",
				'icon' => "symb-orange.png",
			);
		
		foreach ($d as $k => $data) {
			$rs = $this->insert($data);
		}
	}

	public function get_grade_smiley($color = false, $single = false)
	{
		unset($get);
		$get['fields'] = "id, name, desc, color, color_code, icon";
		$get['order'] = 'level';
		
		if($color !== false){
			$get['where']['color'] = $color;
		}

		if($single){
			$get['single'] = TRUE;
		}


		$rs = $this->get_record(false, $get);

		if(!$rs){
			$this->create_default_data();
			return $this->get_record(false, $get);
		}

		return $rs;
	}
}